Bookmark
How to calculate the alignment between BERT and spaCy tokens effectively and robustly
https://gist.github.com/tamuhey/af6cbb44a703423556c32798e1e1b704, posted 2021 by peter in development free language nlp opensource software toread
Suppose we want to combine a BERT-based named entity recognition (NER) model with a rule-based NER model built on top of spaCy. Although BERT's NER exhibits extremely high performance, it is usually combined with rule-based approaches for practical purposes. In such cases, what often bothers us is that tokens of spaCy and BERT are different, even if the input sentences are the same. For example, let's say the input sentence is "John Johanson 's house"; BERT tokenizes this sentence like
["john", "johan", "##son", "'", "s", "house"]
and spaCy tokenizes it like["John", "Johanson", "'s", "house"]
. To combine the outputs, we need to calculate the correspondence between the two different token sequences. This correspondence is the "alignment".